package com.ruoyi.carShopService.controller;

import com.ruoyi.carShopService.domain.CarOrders1;
import com.ruoyi.carShopService.domain.WithDrawal;
import com.ruoyi.carShopService.service.WithDrawalService;
import com.ruoyi.carShopService.util.JwtUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.api.domain.CarAccount;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

@RestController
@RequestMapping("/consume")
@CrossOrigin
public class WithDrawalController extends BaseController {
@Autowired
    private WithDrawalService withDrawalService;
    @GetMapping
    public AjaxResult sreachById(@RequestHeader String token) throws Exception {
        Claims claims = JwtUtil.parseJWT(token);
        String subject = claims.getSubject();
        Integer id = Integer.parseInt(subject);
        System.out.println(id);
        WithDrawal withDrawal=withDrawalService.sreachById(id);
        return success(withDrawal);
    }
    @GetMapping("/counttixian")
    public AjaxResult sreachsuntixianById(@RequestHeader String token) throws Exception {
        Claims claims = JwtUtil.parseJWT(token);
        String subject = claims.getSubject();
        Integer id = Integer.parseInt(subject);
        return success(withDrawalService.sreachsuntixianById(id));
    }
    @GetMapping("/count")
    public AjaxResult sreachleijishouruById(@RequestHeader String token) throws Exception {
        Claims claims = JwtUtil.parseJWT(token);
        String subject = claims.getSubject();
        Integer id = Integer.parseInt(subject);
        return success(withDrawalService.sreachleijishouruById(id));
    }
    @GetMapping("/list1")
    public TableDataInfo sreachList1ById(@RequestHeader String token) throws Exception {
        startPage();
        Claims claims = JwtUtil.parseJWT(token);
        String subject = claims.getSubject();
        Integer id = Integer.parseInt(subject);
        List<CarOrders1> list = withDrawalService.sreachList1ById(id);
        return getDataTable(list);
    }
    @GetMapping("/list2")
    public TableDataInfo sreachList2ById(@RequestHeader String token) throws Exception {
        startPage();
        Claims claims = JwtUtil.parseJWT(token);
        String subject = claims.getSubject();
        Integer id = Integer.parseInt(subject);
        List<WithDrawal> list = withDrawalService.sreachList2ById(id);
        return getDataTable(list);
    }
    @PostMapping("/add")
    public AjaxResult addnewjilu(@RequestBody WithDrawal withDrawal,@RequestHeader String token) throws Exception {
        Claims claims = JwtUtil.parseJWT(token);
        String subject = claims.getSubject();
        Integer id = Integer.parseInt(subject);
        WithDrawal withDrawal1=new WithDrawal();
        withDrawal1.setWdmerchantId(id);
        withDrawal1.setWdcashWithdrawal(withDrawal.getWdcashWithdrawal());
        withDrawal1.setWdrealName(withDrawal.getWdrealName());
        withDrawal1.setWdbankcardNumber(withDrawal.getWdbankcardNumber());
        withDrawal1.setWdwithdrawalRecord(withDrawal.getWdwithdrawalRecord());
        withDrawal1.setWdcurrentBalance(withDrawal.getWdcurrentBalance());
        return success(withDrawalService.addnewjilu(withDrawal1));
    }
}
